package com.atmilan.quartz.service.impl;

import com.atmilan.quartz.constant.enums.CategoryTypeEnum;
import com.atmilan.quartz.constant.enums.ProductTypeEnum;
import com.atmilan.quartz.model.entity.crmeb.SupplierUnmatchCategory;
import com.atmilan.quartz.service.ISupplierUnmatchCategoryService;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.atmilan.quartz.mapper.CategoryMatchMapper;
import com.atmilan.quartz.model.entity.crmeb.CategoryMatch;
import com.atmilan.quartz.service.ICategoryMatchService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

@Service
public class CategoryMatchServiceImpl extends ServiceImpl<CategoryMatchMapper, CategoryMatch> implements ICategoryMatchService {

    @Autowired
    ISupplierUnmatchCategoryService supplierUnmatchCategoryService;

    @Override
    public void unMatchCategory(CategoryMatch categoryMatch, String firstCate, String secondCate, String thirdCate, CategoryTypeEnum typeEnum) {
        if(categoryMatch == null){
            int count = supplierUnmatchCategoryService.count(Wrappers.<SupplierUnmatchCategory>lambdaQuery()
                    .eq(SupplierUnmatchCategory::getType, typeEnum)
                    .eq(SupplierUnmatchCategory::getIsDel,0)
                    .eq(firstCate != null,SupplierUnmatchCategory::getFirstCate, firstCate)
                    .eq(secondCate != null,SupplierUnmatchCategory::getSecondCate, secondCate)
                    .eq(thirdCate != null,SupplierUnmatchCategory::getThirdCate,thirdCate)
            );
            if(count < 1){
                SupplierUnmatchCategory supplierUnmatchCategory = new SupplierUnmatchCategory();
                supplierUnmatchCategory.setType(typeEnum.getCode());
                supplierUnmatchCategory.setFirstCate(firstCate);
                supplierUnmatchCategory.setSecondCate(secondCate);
                supplierUnmatchCategory.setThirdCate(thirdCate);
                supplierUnmatchCategoryService.save(supplierUnmatchCategory);
            }
        }
    }

}
